<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="zh-CN" xml:lang="zh-CN">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
		<meta charset="UTF-8" />
		<title>我的订单</title>
		<meta name="description" content="" />
		<meta name="keywords" content="" />
		<meta name="viewport" content="width=1226" />
		<meta http-equiv="Cache-Control" content="no-transform " />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="stylesheet" href="../xiaomi/css/base.min.css" />
		<link rel="stylesheet" href="../xiaomi/css/main.min.css" />
		<link rel="stylesheet" href="../css/xiaomi.css" />
		<script type="text/javascript" src="../js/jquery-2.1.4.min.js"></script>
    	<script src="../js/jquery.animate-colors-min.js"></script>
		<script>
			var page = 1;
	    	var type = 2;
		    $(function(){
				list();
			});
		    function updateOrders(id) {
		    	if (confirm("真的要确认收货吗？")) {
		    		window.location.href="ordersUpdate?id=" + id + "&status=3";
// 		    		$.ajax({
// 					    url: "ordersUpdate?id=" + id + "&status=3",
// 					    type: "GET",
// 					    dataType: "json",
// 					    async: false,
// 					    success: function(data) {
// 					        if(data.status==1){
// 					        	var list = data.list;
// 					        	var status = "";
// 					        }
// 					    }
// 					});
		    	} else {
		    		return false;
		    	}
		    	
		    }
		    
			function list(){
			$.ajax({
			    url: "ordersList?type="+type+"&p="+page,
			    type: "GET",
			    dataType: "json",
			    async: false,
			    success: function(data) {
			        if(data.status==1){
			        	var list = data.list;
			        	var status = "";
			        	for(var i=0;i<list.length;i++){
			        		var buttonStr = "";
			        		if(list[i].status=="0"){
			        			status = "未付款";
			        			buttonStr = '				<td class="order-actions">'
								+ '					<a class="btn btn-small btn-primary">立即支付</a>'
								+ '				</td>';
								continue;
			        		} else if (list[i].status=="1") {
			        			status = "待发货";
			        		} else if (list[i].status=="2") {
			        			status = "待收货";
			        			buttonStr = '				<td class="order-actions">'
									+ '					<a class="btn btn-small btn-primary" onclick="updateOrders('+list[i].id+', 3)" >确认收货</a>'
									+ '				</td>';
			        		} else {
			        			status = "已成功";
			        		}
			        		var d = new Date(list[i].createDate);
			        		var date = d.getFullYear() + "-";
								date+=("0"+(d.getMonth()+1)).slice(-2) + "-";
								date+= ("0"+d.getDate()).slice(-2) + " ";
								date+= ("0"+d.getHours()).slice(-2) + ":";	   
								date+= ("0"+d.getMinutes()).slice(-2) + ":";
								date+=("0"+d.getSeconds()).slice(-2);
// 			        		$("#orderList").append("<div class='order-list' id='"+list[i].id+"'><a href='ordersDetail?no="+list[i].no+"'><div class='cart-title wbox'><div class='of f30'>订单号&nbsp;&nbsp;"+list[i].no+"</div><div class='wbox-flex tr sn-txt-muted'>应付款 <i class='f30 sn-txt-black'> ￥"+list[i].money+" </i></div></div></a><ul class='order-pro-list order-box'><li id='"+list[i].id+"_'><a href='ordersDetail?no="+list[i].no+"' class='pro-list'><div class='wbox'><div class='pro-info wbox-flex'><div class='pro-name text-clamp2 fs26'>"+list[i].productName+"</div><div class='snPrice sn-txt-black fs30'>"+date+"</div><div class='list-opra sn-txt-muted'>"+status+"&nbsp;&nbsp;&nbsp;&nbsp;数量："+list[i].productNum+"</div></div></div></a></li></ul></div>");
			        		var htmlStr = '<div id="J_orderList">'
									+ '<ul class="order-list">'
									+ '<li class="uc-order-item uc-order-item-pay">'
									+ '<div class="order-detail">'
									+ '<table class="order-detail-table">'
									+ '		<thead>'
									+ '			<tr>'
									+ '				<th class="col-main">'
									+ '					<p class="caption-info">' + date
									+ '						<span class="sep">|</span>订单号：' +list[i].no
									+ '						<span class="sep">|</span>状态：' +status
									+ '					</p>'
									+ '				</th>'
									+ '				<th class="col-sub">'
									+ '				<p class="caption-price">订单金额：'
									+ '				<span class="num">'+list[i].money+'</span>元'
									+ '				</p>'
									+ '				</th>'
									+ '			</tr>'
									+ '		</thead>'
									+ '		<tbody>'
									+ '			<tr>'
									+ '				<td class="order-items">'
									+ '					<ul class="goods-list">'
									+ '						<li>'
// 									+ '						<div class="figure figure-thumb">'
// 									+ '							<a href="#" target="blank">'
// 									+ '							<img src="//i1.mifile.cn/a1/T1IdZgB5hv1RXrhCrK!80x80.jpg" width="80" height="80" alt="'+list[i].productName+'">'
// 									+ '							</a>'
// 									+ '						</div>'
									+ '						<p class="name">'+list[i].productName
									+ '						</p>'
									+ '						</li>'
									+ '					</ul>'
									+ '				</td>'
									+ buttonStr
									+ '			</tr>'
									+ '		</tbody>'
									+ '	</table>'
									+ '</div>'
									+ '</li>'
									+ '</ul>'
									+ '</div>';
							$("#orderList").append(htmlStr);
			        	}
// 			        	$("#nextPage").html("点击加载更多");
// 			        	$("#nextPage").attr("style","display:");
// 			        	$("#noLoadNextPage").attr("style","display:none");
// 			        	if(data.isNextPage==0){
// 			        		$("#nextPage").html("已全部加载完");
// 			        		$("#nextPage").attr("style","display:none");
// 			        		$("#noLoadNextPage").attr("style","display:");
// 			        	}
			        	page ++;
			        }
			    }
			});
		}
    </script>
</head>
<body>
	<jsp:include page="../head.jsp" />
	<div class="breadcrumbs">
		<div class="container">
			<a href="index.jsp">首页</a><span class="sep">&gt;</span><span>交易订单</span>
		</div>
	</div>
	<div class="page-main user-main">
		<div class="container">
			<div class="row">
				<div class="span4">
					<div class="uc-box uc-sub-box">
						<div class="uc-nav-box">
							<div class="box-hd">
								<h3 class="title">订单中心</h3>
							</div>
							<div class="box-bd">
								<ul class="uc-nav-list J_navList">
									<li class="active"><a class="J_noRandom"
										href="<%=basePath%>user/ordersList.jsp">我的订单</a></li>
									<li><a href="<%=basePath%>user/index.jsp">个人信息</a></li>
								</ul>
							</div>
						</div>
					</div>
				</div>
				<div class="span16">
					<div class="uc-box uc-main-box">
						<div class="uc-content-box order-list-box">
							<div class="box-hd">
								<h1 class="title">我的订单</h1>
							</div>
							<div id="orderList" class="box-bd">
							</div>
<!-- 							<div id="J_orderListPages"> -->
<!-- 									<div class="xm-pagenavi"> -->
<!-- 										<span class="numbers first"> -->
<!-- 										<span class="iconfont"><</span> -->
<!-- 										</span> -->
<!-- 										<span class="numbers current">1</span> -->
<!-- 										<span class="numbers last"> -->
<!-- 										<span class="iconfont">></span> -->
<!-- 										</span> -->
<!-- 									</div> -->
<!-- 								</div> -->
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<jsp:include page="../bottom.jsp" />
</body>
</html>
